# -*- coding: utf-8 -*-
"""
@Author: 王少杰
@Date: 2025/8/28
@Time: 10:35
@FileName: ReadCsv.py
@描述:
"""
import csv
from os.path import abspath, dirname, join
class ReadCsv:
    curr_file_path = abspath(__file__)
    project_path = dirname(dirname(dirname(curr_file_path)))
    def read_case_data(self, file_name, row):
        """
        :param file_name:用来接收要读取文件的名称。即data目录下的文件名称
        :param row:要读取csv文件中对应的行号
        :return:返回某一个测试用例数据，是一个列表
        """
        # 起始路径:D:\HospitalProject\pythonProject1\src\common\ReadCsv.py
        # 结束路径:D:\HospitalProject\pythonProject1\data\login_case_data.csv
        case_file_path = join(self.project_path, "data", file_name)
        with open(case_file_path, "r", encoding="utf-8") as f:
            csv_reader = csv.reader(f)
            case_data = list(csv_reader)
            return case_data[ row - 1 ]
    def read_config(self, file_name):
        config_path = join(self.project_path, "config", file_name)
        with open(config_path, "r", encoding="utf-8") as f:
            config_reader = csv.reader(f)
            config_data = dict(config_reader)
            return config_data
read_csv_obj = ReadCsv()
if __name__ == '__main__':
    print(ReadCsv().read_case_data("login_case_data.csv", 2))
    print(ReadCsv().read_config("url.csv")['url'])